<?php

namespace app\controller;

use app\BaseController;
use think\facade\Config;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;

class Order extends Common
{

    // http://www.penyou.com/Order/add
    public function add()
    {
        $package_id = Request::param('package_id');
        $vip_info = Db::name('vips')->field('title,price,duration')->where(array('id' => $package_id))->find();

        $data = array(
            'uid' => $this->userId,
            'title' => $vip_info['title'],
            'type' => 'vip',
            'order_no' => date("YmdHis") . random_int(10000, 99999),
            'order_money' => $vip_info['price'],
            'create_date' => date('Y-m-d H:i:s'),
            'duration' => $vip_info['duration']
        );
        $lastId = Db::name('pay')->insertGetId($data);

        singleJson($lastId, '生成订单异常');
    }


}
